package com.inco.cloud.server2.service.impl;

import com.inco.cloud.server2.feign.service.FeignService;
import com.inco.cloud.server2.mapper.UserDao;
import com.inco.cloud.server2.service.UserService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    //注入Mapper
    @Autowired
    private UserDao userDao;

    //注入远程调用服务
    @Autowired
    private FeignService feignService;

    /**
     * 远程调用
     * @param appName
     * @return
     */
    @Override
    public String helloAppName(String appName) {
        return feignService.helloAppName(appName);
    }

    //分布式事务
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer addUser(String userId, String username) {
        return userDao.addUser("server2-"+userId,"server2-"+username);
    }
}